import { createSlice } from '@reduxjs/toolkit'
import axios from 'axios'
const channelStore = createSlice({
    name: 'channel',
    initialState: {
        channelList: [],
    },
    reducers: {
        setChannelList(state, action) {
            state.channelList = action.payload
        },
    },
})

const channelInfo = channelStore.reducer

const channelFuns = {
    fetchChannelList: () => {
        return async dispatch => {
            const res = await axios.get('http://localhost:3004/getChannelList')
            dispatch(channelStore.actions.setChannelList(res.data.value))
        }
    },
}

export { channelInfo, channelFuns }
